1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package java.security;
27
28 import java.security.spec.AlgorithmParameterSpec;
29 import java.util.*;
30 import java.util.concurrent.ConcurrentHashMap;
31 import java.io.*;
32 import java.security.cert.Certificate;
33 import java.security.cert.X509Certificate;
34
35 import java.nio.ByteBuffer;
36
37 import java.security.Provider.Service;
38
39 import javax.crypto.Cipher;
40 import javax.crypto.CipherSpi;
41 import javax.crypto.IllegalBlockSizeException;
42 import javax.crypto.BadPaddingException;
43 import javax.crypto.NoSuchPaddingException;
44
45 import sun.security.util.Debug;
46 import sun.security.jca.*;
47 import sun.security.jca.GetInstance.Instance;
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119 public abstract class Signature extends SignatureSpi {
120
121 private static final Debug debug =
122 Debug.getInstance("jca", "Signature");
123
124
125
126
127
128
129 private String algorithm;
130
131
132 Provider provider;
133
134
135
136
137
138 protected final static int UNINITIALIZED = 0;
139
140
141
142
143
144 protected final static int SIGN = 2;
145
146
147
148
149
150 protected final static int VERIFY = 3;
151
152
153
154
155 protected int state = UNINITIALIZED;
156
157
158
159
160
161
162
163
164
165
166 protected Signature(String algorithm) {
167 this.algorithm = algorithm;
168 }
169
170
171 private final static String RSA_SIGNATURE = "NONEwithRSA";
172
173
174 private final static String RSA_CIPHER = "RSA/ECB/PKCS1Padding";
175
176
177 private final static List<ServiceId> rsaIds = Arrays.asList(
178 new ServiceId[] {
179 new ServiceId("Signature", "NONEwithRSA"),
180 new ServiceId("Cipher", "RSA/ECB/PKCS1Padding"),
181 new ServiceId("Cipher", "RSA/ECB"),
182 new ServiceId("Cipher", "RSA//PKCS1Padding"),
183 new ServiceId("Cipher", "RSA"),
184 }
185 );
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214 public static Signature getInstance(String algorithm)
215 throws NoSuchAlgorithmException {
216 List<Service> list;
217 if (algorithm.equalsIgnoreCase(RSA_SIGNATURE)) {
218 list = GetInstance.getServices(rsaIds);
219 } else {
220 list = GetInstance.getServices("Signature", algorithm);
221 }
222 Iterator<Service> t = list.iterator();
223 if (t.hasNext() == false) {
224 throw new NoSuchAlgorithmException
225 (algorithm + " Signature not available");
226 }
227
228 NoSuchAlgorithmException failure;
229 do {
230 Service s = t.next();
231 if (isSpi(s)) {
232 return new Delegate(s, t, algorithm);
233 } else {
234
235 try {
236 Instance instance =
237 GetInstance.getInstance(s, SignatureSpi.class);
238 return getInstance(instance, algorithm);
239 } catch (NoSuchAlgorithmException e) {
240 failure = e;
241 }
242 }
243 } while (t.hasNext());
244 throw failure;
245 }
246
247 private static Signature getInstance(Instance instance, String algorithm) {
248 Signature sig;
249 if (instance.impl instanceof Signature) {
250 sig = (Signature)instance.impl;
251 } else {
252 SignatureSpi spi = (SignatureSpi)instance.impl;
253 sig = new Delegate(spi, algorithm);
254 }
255 sig.provider = instance.provider;
256 return sig;
257 }
258
259 private final static Map<String,Boolean> signatureInfo;
260
261 static {
262 signatureInfo = new ConcurrentHashMap<String,Boolean>();
263 Boolean TRUE = Boolean.TRUE;
264
265 signatureInfo.put("sun.security.provider.DSA$RawDSA", TRUE);
266 signatureInfo.put("sun.security.provider.DSA$SHA1withDSA", TRUE);
267 signatureInfo.put("sun.security.rsa.RSASignature$MD2withRSA", TRUE);
268 signatureInfo.put("sun.security.rsa.RSASignature$MD5withRSA", TRUE);
269 signatureInfo.put("sun.security.rsa.RSASignature$SHA1withRSA", TRUE);
270 signatureInfo.put("sun.security.rsa.RSASignature$SHA256withRSA", TRUE);
271 signatureInfo.put("sun.security.rsa.RSASignature$SHA384withRSA", TRUE);
272 signatureInfo.put("sun.security.rsa.RSASignature$SHA512withRSA", TRUE);
273 signatureInfo.put("com.sun.net.ssl.internal.ssl.RSASignature", TRUE);
274 signatureInfo.put("sun.security.pkcs11.P11Signature", TRUE);
275 }
276
277 private static boolean isSpi(Service s) {
278 if (s.getType().equals("Cipher")) {
279
280 return true;
281 }
282 String className = s.getClassName();
283 Boolean result = signatureInfo.get(className);
284 if (result == null) {
285 try {
286 Object instance = s.newInstance(null);
287
288
289
290 boolean r = (instance instanceof SignatureSpi)
291 && (instance instanceof Signature == false);
292 if ((debug != null) && (r == false)) {
293 debug.println("Not a SignatureSpi " + className);
294 debug.println("Delayed provider selection may not be "
295 + "available for algorithm " + s.getAlgorithm());
296 }
297 result = Boolean.valueOf(r);
298 signatureInfo.put(className, result);
299 } catch (Exception e) {
300
301 return false;
302 }
303 }
304 return result.booleanValue();
305 }
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341 public static Signature getInstance(String algorithm, String provider)
342 throws NoSuchAlgorithmException, NoSuchProviderException {
343 if (algorithm.equalsIgnoreCase(RSA_SIGNATURE)) {
344
345 if ((provider == null) || (provider.length() == 0)) {
346 throw new IllegalArgumentException("missing provider");
347 }
348 Provider p = Security.getProvider(provider);
349 if (p == null) {
350 throw new NoSuchProviderException
351 ("no such provider: " + provider);
352 }
353 return getInstanceRSA(p);
354 }
355 Instance instance = GetInstance.getInstance
356 ("Signature", SignatureSpi.class, algorithm, provider);
357 return getInstance(instance, algorithm);
358 }
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389 public static Signature getInstance(String algorithm, Provider provider)
390 throws NoSuchAlgorithmException {
391 if (algorithm.equalsIgnoreCase(RSA_SIGNATURE)) {
392
393 if (provider == null) {
394 throw new IllegalArgumentException("missing provider");
395 }
396 return getInstanceRSA(provider);
397 }
398 Instance instance = GetInstance.getInstance
399 ("Signature", SignatureSpi.class, algorithm, provider);
400 return getInstance(instance, algorithm);
401 }
402
403
404
405 private static Signature getInstanceRSA(Provider p)
406 throws NoSuchAlgorithmException {
407
408 Service s = p.getService("Signature", RSA_SIGNATURE);
409 if (s != null) {
410 Instance instance = GetInstance.getInstance(s, SignatureSpi.class);
411 return getInstance(instance, RSA_SIGNATURE);
412 }
413
414 try {
415 Cipher c = Cipher.getInstance(RSA_CIPHER, p);
416 return new Delegate(new CipherAdapter(c), RSA_SIGNATURE);
417 } catch (GeneralSecurityException e) {
418
419
420 throw new NoSuchAlgorithmException("no such algorithm: "
421 + RSA_SIGNATURE + " for provider " + p.getName(), e);
422 }
423 }
424
425
426
427
428
429
430 public final Provider getProvider() {
431 chooseFirstProvider();
432 return this.provider;
433 }
434
435 void chooseFirstProvider() {
436
437 }
438
439
440
441
442
443
444
445
446
447
448
449 public final void initVerify(PublicKey publicKey)
450 throws InvalidKeyException {
451 engineInitVerify(publicKey);
452 state = VERIFY;
453 }
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473 public final void initVerify(Certificate certificate)
474 throws InvalidKeyException {
475
476
477
478 if (certificate instanceof java.security.cert.X509Certificate) {
479
480
481
482 X509Certificate cert = (X509Certificate)certificate;
483 Set<String> critSet = cert.getCriticalExtensionOIDs();
484
485 if (critSet != null && !critSet.isEmpty()
486 && critSet.contains("2.5.29.15")) {
487 boolean[] keyUsageInfo = cert.getKeyUsage();
488
489 if ((keyUsageInfo != null) && (keyUsageInfo[0] == false))
490 throw new InvalidKeyException("Wrong key usage");
491 }
492 }
493
494 PublicKey publicKey = certificate.getPublicKey();
495 engineInitVerify(publicKey);
496 state = VERIFY;
497 }
498
499
500
501
502
503
504
505
506
507
508
509 public final void initSign(PrivateKey privateKey)
510 throws InvalidKeyException {
511 engineInitSign(privateKey);
512 state = SIGN;
513 }
514
515
516
517
518
519
520
521
522
523
524
525
526
527 public final void initSign(PrivateKey privateKey, SecureRandom random)
528 throws InvalidKeyException {
529 engineInitSign(privateKey, random);
530 state = SIGN;
531 }
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551 public final byte[] sign() throws SignatureException {
552 if (state == SIGN) {
553 return engineSign();
554 }
555 throw new SignatureException("object not initialized for " +
556 "signing");
557 }
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587 public final int sign(byte[] outbuf, int offset, int len)
588 throws SignatureException {
589 if (outbuf == null) {
590 throw new IllegalArgumentException("No output buffer given");
591 }
592 if (outbuf.length - offset < len) {
593 throw new IllegalArgumentException
594 ("Output buffer too small for specified offset and length");
595 }
596 if (state != SIGN) {
597 throw new SignatureException("object not initialized for " +
598 "signing");
599 }
600 return engineSign(outbuf, offset, len);
601 }
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621 public final boolean verify(byte[] signature) throws SignatureException {
622 if (state == VERIFY) {
623 return engineVerify(signature);
624 }
625 throw new SignatureException("object not initialized for " +
626 "verification");
627 }
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657 public final boolean verify(byte[] signature, int offset, int length)
658 throws SignatureException {
659 if (state == VERIFY) {
660 if ((signature == null) || (offset < 0) || (length < 0) ||
661 (offset + length > signature.length)) {
662 throw new IllegalArgumentException("Bad arguments");
663 }
664
665 return engineVerify(signature, offset, length);
666 }
667 throw new SignatureException("object not initialized for " +
668 "verification");
669 }
670
671
672
673
674
675
676
677
678
679 public final void update(byte b) throws SignatureException {
680 if (state == VERIFY || state == SIGN) {
681 engineUpdate(b);
682 } else {
683 throw new SignatureException("object not initialized for "
684 + "signature or verification");
685 }
686 }
687
688
689
690
691
692
693
694
695
696
697 public final void update(byte[] data) throws SignatureException {
698 update(data, 0, data.length);
699 }
700
701
702
703
704
705
706
707
708
709
710
711
712 public final void update(byte[] data, int off, int len)
713 throws SignatureException {
714 if (state == SIGN || state == VERIFY) {
715 engineUpdate(data, off, len);
716 } else {
717 throw new SignatureException("object not initialized for "
718 + "signature or verification");
719 }
720 }
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735 public final void update(ByteBuffer data) throws SignatureException {
736 if ((state != SIGN) && (state != VERIFY)) {
737 throw new SignatureException("object not initialized for "
738 + "signature or verification");
739 }
740 if (data == null) {
741 throw new NullPointerException();
742 }
743 engineUpdate(data);
744 }
745
746
747
748
749
750
751 public final String getAlgorithm() {
752 return this.algorithm;
753 }
754
755
756
757
758
759
760
761
762 public String toString() {
763 String initState = "";
764 switch (state) {
765 case UNINITIALIZED:
766 initState = "<not initialized>";
767 break;
768 case VERIFY:
769 initState = "<initialized for verifying>";
770 break;
771 case SIGN:
772 initState = "<initialized for signing>";
773 break;
774 }
775 return "Signature object: " + getAlgorithm() + initState;
776 }
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803 @Deprecated
804 public final void setParameter(String param, Object value)
805 throws InvalidParameterException {
806 engineSetParameter(param, value);
807 }
808
809
810
811
812
813
814
815
816
817
818
819 public final void setParameter(AlgorithmParameterSpec params)
820 throws InvalidAlgorithmParameterException {
821 engineSetParameter(params);
822 }
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839 public final AlgorithmParameters getParameters() {
840 return engineGetParameters();
841 }
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866 @Deprecated
867 public final Object getParameter(String param)
868 throws InvalidParameterException {
869 return engineGetParameter(param);
870 }
871
872
873
874
875
876
877
878
879
880 public Object clone() throws CloneNotSupportedException {
881 if (this instanceof Cloneable) {
882 return super.clone();
883 } else {
884 throw new CloneNotSupportedException();
885 }
886 }
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902 private static class Delegate extends Signature {
903
904
905
906 private SignatureSpi sigSpi;
907
908
909 private final Object lock;
910
911
912
913 private Service firstService;
914
915
916
917 private Iterator<Service> serviceIterator;
918
919
920 Delegate(SignatureSpi sigSpi, String algorithm) {
921 super(algorithm);
922 this.sigSpi = sigSpi;
923 this.lock = null;
924 }
925
926
927 Delegate(Service service,
928 Iterator<Service> iterator, String algorithm) {
929 super(algorithm);
930 this.firstService = service;
931 this.serviceIterator = iterator;
932 this.lock = new Object();
933 }
934
935
936
937
938
939
940
941
942
943 public Object clone() throws CloneNotSupportedException {
944 chooseFirstProvider();
945 if (sigSpi instanceof Cloneable) {
946 SignatureSpi sigSpiClone = (SignatureSpi)sigSpi.clone();
947
948
949
950 Signature that =
951 new Delegate(sigSpiClone, ((Signature)this).algorithm);
952 that.provider = ((Signature)this).provider;
953 return that;
954 } else {
955 throw new CloneNotSupportedException();
956 }
957 }
958
959 private static SignatureSpi newInstance(Service s)
960 throws NoSuchAlgorithmException {
961 if (s.getType().equals("Cipher")) {
962
963 try {
964 Cipher c = Cipher.getInstance(RSA_CIPHER, s.getProvider());
965 return new CipherAdapter(c);
966 } catch (NoSuchPaddingException e) {
967 throw new NoSuchAlgorithmException(e);
968 }
969 } else {
970 Object o = s.newInstance(null);
971 if (o instanceof SignatureSpi == false) {
972 throw new NoSuchAlgorithmException
973 ("Not a SignatureSpi: " + o.getClass().getName());
974 }
975 return (SignatureSpi)o;
976 }
977 }
978
979
980 private static int warnCount = 10;
981
982
983
984
985
986
987 void chooseFirstProvider() {
988 if (sigSpi != null) {
989 return;
990 }
991 synchronized (lock) {
992 if (sigSpi != null) {
993 return;
994 }
995 if (debug != null) {
996 int w = --warnCount;
997 if (w >= 0) {
998 debug.println("Signature.init() not first method "
999 + "called, disabling delayed provider selection");
1000 if (w == 0) {
1001 debug.println("Further warnings of this type will "
1002 + "be suppressed");
1003 }
1004 new Exception("Call trace").printStackTrace();
1005 }
1006 }
1007 Exception lastException = null;
1008 while ((firstService != null) || serviceIterator.hasNext()) {
1009 Service s;
1010 if (firstService != null) {
1011 s = firstService;
1012 firstService = null;
1013 } else {
1014 s = serviceIterator.next();
1015 }
1016 if (isSpi(s) == false) {
1017 continue;
1018 }
1019 try {
1020 sigSpi = newInstance(s);
1021 provider = s.getProvider();
1022
1023 firstService = null;
1024 serviceIterator = null;
1025 return;
1026 } catch (NoSuchAlgorithmException e) {
1027 lastException = e;
1028 }
1029 }
1030 ProviderException e = new ProviderException
1031 ("Could not construct SignatureSpi instance");
1032 if (lastException != null) {
1033 e.initCause(lastException);
1034 }
1035 throw e;
1036 }
1037 }
1038
1039 private void chooseProvider(int type, Key key, SecureRandom random)
1040 throws InvalidKeyException {
1041 synchronized (lock) {
1042 if (sigSpi != null) {
1043 init(sigSpi, type, key, random);
1044 return;
1045 }
1046 Exception lastException = null;
1047 while ((firstService != null) || serviceIterator.hasNext()) {
1048 Service s;
1049 if (firstService != null) {
1050 s = firstService;
1051 firstService = null;
1052 } else {
1053 s = serviceIterator.next();
1054 }
1055
1056 if (s.supportsParameter(key) == false) {
1057 continue;
1058 }
1059
1060 if (isSpi(s) == false) {
1061 continue;
1062 }
1063 try {
1064 SignatureSpi spi = newInstance(s);
1065 init(spi, type, key, random);
1066 provider = s.getProvider();
1067 sigSpi = spi;
1068 firstService = null;
1069 serviceIterator = null;
1070 return;
1071 } catch (Exception e) {
1072
1073
1074
1075 if (lastException == null) {
1076 lastException = e;
1077 }
1078 }
1079 }
1080
1081 if (lastException instanceof InvalidKeyException) {
1082 throw (InvalidKeyException)lastException;
1083 }
1084 if (lastException instanceof RuntimeException) {
1085 throw (RuntimeException)lastException;
1086 }
1087 String k = (key != null) ? key.getClass().getName() : "(null)";
1088 throw new InvalidKeyException
1089 ("No installed provider supports this key: "
1090 + k, lastException);
1091 }
1092 }
1093
1094 private final static int I_PUB = 1;
1095 private final static int I_PRIV = 2;
1096 private final static int I_PRIV_SR = 3;
1097
1098 private void init(SignatureSpi spi, int type, Key key,
1099 SecureRandom random) throws InvalidKeyException {
1100 switch (type) {
1101 case I_PUB:
1102 spi.engineInitVerify((PublicKey)key);
1103 break;
1104 case I_PRIV:
1105 spi.engineInitSign((PrivateKey)key);
1106 break;
1107 case I_PRIV_SR:
1108 spi.engineInitSign((PrivateKey)key, random);
1109 break;
1110 default:
1111 throw new AssertionError("Internal error: " + type);
1112 }
1113 }
1114
1115 protected void engineInitVerify(PublicKey publicKey)
1116 throws InvalidKeyException {
1117 if (sigSpi != null) {
1118 sigSpi.engineInitVerify(publicKey);
1119 } else {
1120 chooseProvider(I_PUB, publicKey, null);
1121 }
1122 }
1123
1124 protected void engineInitSign(PrivateKey privateKey)
1125 throws InvalidKeyException {
1126 if (sigSpi != null) {
1127 sigSpi.engineInitSign(privateKey);
1128 } else {
1129 chooseProvider(I_PRIV, privateKey, null);
1130 }
1131 }
1132
1133 protected void engineInitSign(PrivateKey privateKey, SecureRandom sr)
1134 throws InvalidKeyException {
1135 if (sigSpi != null) {
1136 sigSpi.engineInitSign(privateKey, sr);
1137 } else {
1138 chooseProvider(I_PRIV_SR, privateKey, sr);
1139 }
1140 }
1141
1142 protected void engineUpdate(byte b) throws SignatureException {
1143 chooseFirstProvider();
1144 sigSpi.engineUpdate(b);
1145 }
1146
1147 protected void engineUpdate(byte[] b, int off, int len)
1148 throws SignatureException {
1149 chooseFirstProvider();
1150 sigSpi.engineUpdate(b, off, len);
1151 }
1152
1153 protected void engineUpdate(ByteBuffer data) {
1154 chooseFirstProvider();
1155 sigSpi.engineUpdate(data);
1156 }
1157
1158 protected byte[] engineSign() throws SignatureException {
1159 chooseFirstProvider();
1160 return sigSpi.engineSign();
1161 }
1162
1163 protected int engineSign(byte[] outbuf, int offset, int len)
1164 throws SignatureException {
1165 chooseFirstProvider();
1166 return sigSpi.engineSign(outbuf, offset, len);
1167 }
1168
1169 protected boolean engineVerify(byte[] sigBytes)
1170 throws SignatureException {
1171 chooseFirstProvider();
1172 return sigSpi.engineVerify(sigBytes);
1173 }
1174
1175 protected boolean engineVerify(byte[] sigBytes, int offset, int length)
1176 throws SignatureException {
1177 chooseFirstProvider();
1178 return sigSpi.engineVerify(sigBytes, offset, length);
1179 }
1180
1181 protected void engineSetParameter(String param, Object value)
1182 throws InvalidParameterException {
1183 chooseFirstProvider();
1184 sigSpi.engineSetParameter(param, value);
1185 }
1186
1187 protected void engineSetParameter(AlgorithmParameterSpec params)
1188 throws InvalidAlgorithmParameterException {
1189 chooseFirstProvider();
1190 sigSpi.engineSetParameter(params);
1191 }
1192
1193 protected Object engineGetParameter(String param)
1194 throws InvalidParameterException {
1195 chooseFirstProvider();
1196 return sigSpi.engineGetParameter(param);
1197 }
1198
1199 protected AlgorithmParameters engineGetParameters() {
1200 chooseFirstProvider();
1201 return sigSpi.engineGetParameters();
1202 }
1203 }
1204
1205
1206 private static class CipherAdapter extends SignatureSpi {
1207
1208 private final Cipher cipher;
1209
1210 private ByteArrayOutputStream data;
1211
1212 CipherAdapter(Cipher cipher) {
1213 this.cipher = cipher;
1214 }
1215
1216 protected void engineInitVerify(PublicKey publicKey)
1217 throws InvalidKeyException {
1218 cipher.init(Cipher.DECRYPT_MODE, publicKey);
1219 if (data == null) {
1220 data = new ByteArrayOutputStream(128);
1221 } else {
1222 data.reset();
1223 }
1224 }
1225
1226 protected void engineInitSign(PrivateKey privateKey)
1227 throws InvalidKeyException {
1228 cipher.init(Cipher.ENCRYPT_MODE, privateKey);
1229 data = null;
1230 }
1231
1232 protected void engineInitSign(PrivateKey privateKey,
1233 SecureRandom random) throws InvalidKeyException {
1234 cipher.init(Cipher.ENCRYPT_MODE, privateKey, random);
1235 data = null;
1236 }
1237
1238 protected void engineUpdate(byte b) throws SignatureException {
1239 engineUpdate(new byte[] {b}, 0, 1);
1240 }
1241
1242 protected void engineUpdate(byte[] b, int off, int len)
1243 throws SignatureException {
1244 if (data != null) {
1245 data.write(b, off, len);
1246 return;
1247 }
1248 byte[] out = cipher.update(b, off, len);
1249 if ((out != null) && (out.length != 0)) {
1250 throw new SignatureException
1251 ("Cipher unexpectedly returned data");
1252 }
1253 }
1254
1255 protected byte[] engineSign() throws SignatureException {
1256 try {
1257 return cipher.doFinal();
1258 } catch (IllegalBlockSizeException e) {
1259 throw new SignatureException("doFinal() failed", e);
1260 } catch (BadPaddingException e) {
1261 throw new SignatureException("doFinal() failed", e);
1262 }
1263 }
1264
1265 protected boolean engineVerify(byte[] sigBytes)
1266 throws SignatureException {
1267 try {
1268 byte[] out = cipher.doFinal(sigBytes);
1269 byte[] dataBytes = data.toByteArray();
1270 data.reset();
1271 return Arrays.equals(out, dataBytes);
1272 } catch (BadPaddingException e) {
1273
1274
1275 return false;
1276 } catch (IllegalBlockSizeException e) {
1277 throw new SignatureException("doFinal() failed", e);
1278 }
1279 }
1280
1281 protected void engineSetParameter(String param, Object value)
1282 throws InvalidParameterException {
1283 throw new InvalidParameterException("Parameters not supported");
1284 }
1285
1286 protected Object engineGetParameter(String param)
1287 throws InvalidParameterException {
1288 throw new InvalidParameterException("Parameters not supported");
1289 }
1290
1291 }
1292
1293 }